import { ref } from "vue";
import { onLoad } from "@dcloudio/uni-app";

/** 返回 */
export const useBack = () => {
  const canBack = ref(false);

  const goBack = () => {
    if (canBack.value) {
      uni.navigateBack();
    } else {
      uni.switchTab({
        url: "/pages/index/index",
      });
    }
  };

  onLoad(() => {
    console.log("useBack onLoad");
    canBack.value = getCurrentPages().length > 1;
  });

  return {
    goBack,
  };
};
